﻿
namespace OZDoo.Core.Caching
{
    /// <summary>
    /// 缓存服务类,提供缓存服务
    /// </summary>
    public sealed class CacheService
    {
        private static ICache _cache;
        /// <summary>
        /// 静态构造函数
        /// </summary>
        static CacheService()
        {
            _cache = CacheManage.GetCache();
        }
        /// <summary>
        /// 清除缓存
        /// </summary>
        public static void Clear()
        {
            _cache.Clear();
        }
        /// <summary>
        /// 获得一个缓存值
        /// </summary>
        /// <param name="key">键值</param>
        /// <returns></returns>
        public static object Get(string key)
        {
            return _cache.Get(key);
        }
        /// <summary>
        /// 插入一个缓冲
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="obj">缓存值</param>
        public static void Insert(string key, object obj)
        {
            _cache.Insert(key, obj);
        }
        /// <summary>
        /// 插入一个缓存值
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="obj">缓存值</param>
        /// <param name="dep">关联</param>
        public static void Insert(string key, object obj, System.Web.Caching.CacheDependency dep)
        {
            _cache.Insert(key, obj, dep);
        }
        /// <summary>
        /// 插入一个缓存值
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="obj">缓存值</param>
        /// <param name="seconds">缓存时间</param>
        /// <param name="priority">相对优先级</param>
        public static void Insert(string key, object obj, int seconds, System.Web.Caching.CacheItemPriority priority)
        {
            _cache.Insert(key, obj, seconds, priority);
        }
        /// <summary>
        /// 插入一个缓存值
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="obj">缓存值</param>
        /// <param name="dep">关联</param>
        /// <param name="seconds">缓存时间</param>
        /// <param name="priority">相对优先级</param>
        public static void Insert(string key, object obj, System.Web.Caching.CacheDependency dep, int seconds, System.Web.Caching.CacheItemPriority priority)
        {
            _cache.Insert(key, obj, dep, seconds, priority);
        }

        /// <summary>
        /// 插入一个缓存值
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="obj">缓存值</param>
        /// <param name="dep">关联</param>
        /// <param name="seconds">缓存时间</param>
        public static void Insert(string key, object obj, System.Web.Caching.CacheDependency dep, int seconds)
        {
            _cache.Insert(key, obj, dep, seconds);
        }
        /// <summary>
        /// 插入一个缓存值
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="obj">缓存值</param>
        /// <param name="seconds">缓存时间</param>
        public static void Insert(string key, object obj, int seconds)
        {
            _cache.Insert(key, obj, seconds);
        }
        /// <summary>
        /// 插入一个缓存值,缓存时间最大化
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="obj">缓存值</param>
        public static void Max(string key, object obj)
        {
            _cache.Max(key, obj);
        }
        /// <summary>
        /// 插入一个缓存值,缓存时间最大化
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="obj">缓存值</param>
        /// <param name="dep">关联</param>
        public static void Max(string key, object obj, System.Web.Caching.CacheDependency dep)
        {
            _cache.Max(key, obj, dep);
        }
        /// <summary>
        /// 插入一个缓存值,缓存时间短暂
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="obj">缓存值</param>
        /// <param name="secondFactor"></param>
        public static void MicroInsert(string key, object obj, int secondFactor)
        {
            _cache.MicroInsert(key, obj, secondFactor);
        }
        /// <summary>
        /// 插入一个缓存值,缓存时间恒定
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="obj">缓存值</param>
        /// <param name="dep">关联</param>
        public static void Permanent(string key, object obj, System.Web.Caching.CacheDependency dep)
        {
            _cache.Permanent(key, obj, dep);
        }
        /// <summary>
        /// 插入一个缓存值,缓存时间恒定
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="obj">缓存值</param>
        public static void Permanent(string key, object obj)
        {
            _cache.Permanent(key, obj);
        }
        /// <summary>
        /// 删除一个缓存值
        /// </summary>
        /// <param name="key"></param>
        public static void Remove(string key)
        {
            _cache.Remove(key);
        }
        /// <summary>
        /// 输出符合条件的缓存值
        /// </summary>
        /// <param name="pattern">模式</param>
        public static void RemoveByPattern(string pattern)
        {
            _cache.RemoveByPattern(pattern);
        }
        public static void ReSetFactor(int cacheFactor)
        {
            _cache.ReSetFactor(cacheFactor);
        }
        public static int SecondFactorCalculate(int seconds)
        {
            return _cache.SecondFactorCalculate(seconds);
        }

        public static string[] GetAllCache()
        {
            return _cache.GetAllCache();
        }
    }
}
